package com.rdxer.core.exception.exceptions;

import com.rdxer.core.entity.StatusCode;
import org.springframework.http.HttpStatus;

public  class BaseException extends RuntimeException {

    HttpStatus httpCode = HttpStatus.BAD_REQUEST;
    Integer code = StatusCode.ERROR;

    public HttpStatus getHttpCode(){return httpCode;};

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public BaseException() {
    }
    public BaseException(String message) {
        super(message);
    }

    public BaseException(String message, Throwable cause) {
        super(message, cause);
    }

    public BaseException(Throwable cause) {
        super(cause);
    }

    public BaseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }


    public static BaseException ofBadRequest(){
        return ofBadRequest("请求错误");
    }
    public static BaseException ofBadRequest(String message){
        BaseException exception = new BaseException(message);
        exception.setCode(StatusCode.ERROR);
        exception.httpCode = HttpStatus.BAD_REQUEST;
        return exception;
    }

    public static BaseException ofForbidden(){
        return ofForbidden("请求被拒绝");
    }
    public static BaseException ofForbidden(String message){
        BaseException exception = new BaseException(message);
        exception.setCode(StatusCode.ACCESSERROR);
        exception.httpCode = HttpStatus.FORBIDDEN;
        return exception;
    }

    public static BaseException ofNotFound(){
        return ofNotFound("资源未找到");
    }

    public static BaseException ofNotFound(String message){
        BaseException exception = new BaseException(message);
        exception.setCode(StatusCode.ERROR);
        exception.httpCode = HttpStatus.NOT_FOUND;
        return exception;
    }






}
